<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    //100.00%
    var sortArrayByParityII = function(A) {
        let len = A.length;
        let arr = new Array(len);
        for(let i=0, even=0, odd=1; i<len; i++){
            if(A[i] % 2 == 0){
                arr[even] = A[i];
                even += 2;
            }else{
                arr[odd] = A[i];
                odd += 2;
            }
        }
        return arr;
    };
    let A = [3,0,4,0,2,1,3,1,3,4];
    console.log(sortArrayByParityII(A));
    
</script>
</html>